package datastructure.leetcode.linked;

import algorithm.sort.Heap;
import common.ListNode;
import org.hibernate.validator.cfg.defs.NotEmptyDef;

/**
 * @author cyt
 * @create 2020-11-22 下午 10:42
 */
public class T206 {
    /**
     * 反转链表
     *
     * @param args
     */
    public static void main(String[] args) {

    }


    public ListNode reverse2(ListNode node) {
        if (node == null || node.next == null) {
            return node;
        }
        ListNode newHead = null;
        while (node != null) {
            ListNode temp = node.next;
            node.next = newHead;
            newHead = node;
            node = temp;
        }
        return newHead;
    }

    public ListNode reverse1(ListNode node) {
        if (node == null || node.next == null) {
            return node;
        }
        ListNode newNode = reverse1(node.next);
        node.next.next = node;
        node.next = null;
        return newNode;
    }
}
